package com.example.admin.brainwave.utils;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.Button;

import com.example.admin.brainwave.R;

public class MyCountDownTimer extends CountDownTimer {


    Button timeButton;
    Context context;

    public MyCountDownTimer(long millisInFuture, long countDownInterval, Button timeButton, Context context) {
        super(millisInFuture, countDownInterval);
        this.timeButton = timeButton;
        this.context = context;
    }

    //计时过程
    @Override
    public void onTick(long l) {
        //防止计时过程中重复点击
        timeButton.setClickable(false);
        timeButton.setText(context.getResources().getString(R.string.resend) + "(" + l / 1000 + "秒)");
        timeButton.setBackground(context.getResources().getDrawable(R.drawable.yzm_button_style));
    }

    //计时完毕的方法
    @Override
    public void onFinish() {
        //重新给Button设置文字
        timeButton.setText(context.getResources().getString(R.string.resend));
        //设置可点击
        timeButton.setClickable(true);
        timeButton.setBackground(context.getResources().getDrawable(R.drawable.main_button_style));
    }

}
